﻿package com.peachcastle.tools
{
	import flash.display.MovieClip;
	import flash.geom.ColorTransform;
	import flash.text.TextField;
	
	/**
	 * 自动调整宽度的文本框
	 * @author Kevin
	 */
	public class AutoWidthBack
	{
		private var _backView:MovieClip = null;
		
		private var _right:MovieClip = null;
		private var _left:MovieClip = null;
		private var _middle:MovieClip = null;
		
		/**
		 * 构造
		 */
		public function AutoWidthBack(backView:MovieClip) 
		{
			_backView = backView;

			_right = _backView.right;
			_middle = _backView.middle;
			_left = _backView.left;
		}
		
		/**
		 * 调整背景宽度
		 * @param	textField
		 */
		public function adjustWidth(textField:TextField):void
		{
			var width:Number = textField.textWidth;
			var x:Number = textField.x;
			textField.width = textField.textWidth+10;
			textField.x = x;
			
			_middle.width = width;
			
			_middle.x = _left.x + _left.width;
			_right.x = _middle.x + _middle.width;
			
			//trace(this, width);
			
		}
		
		/**
		 * 是否显示
		 * @param	isShow
		 */
		public function showBack(isShow:Boolean):void
		{
			_backView.visible = isShow;
		}
		
		
		/**
		 * 设置颜色
		 * @param	color
		 */
		public function setColor(color:int):void
		{
			var colorTransform:ColorTransform = new ColorTransform();
			colorTransform.color = color;
			_backView.transform.colorTransform = colorTransform;
		}
		
	}

}